package cn.edu.dlmu.cogo.framework.data;

import cn.edu.dlmu.cogo.framework.config.DataBaseConfig;
import cn.edu.dlmu.cogo.framework.config.JavaConfig;
import cn.hutool.db.ds.simple.SimpleDataSource;

import javax.sql.DataSource;

/**
 * @author yixi
 * JDBC数据源
 */
public class DataBaseSource {

    private final DataSource dataSource;

    private static class Holder {
        private static final DataBaseSource INSTANCE = new DataBaseSource();
    }

    private DataBaseSource() {
        DataBaseConfig dataBaseConfig = JavaConfig.getConfig(DataBaseConfig.class);
        dataSource = new SimpleDataSource(
                "jdbc:mysql://localhost:3306/" +
                dataBaseConfig.getDataBaseName(),
                dataBaseConfig.getUserName(),
                dataBaseConfig.getPassWord());
    }

    public static DataSource getDataSource(){
        return Holder.INSTANCE.dataSource;
    }
}
